// Functions to take control of the user action
// Cancels the current action
function cancelAction(){

	if ( (event.srcElement.type == "text" || event.srcElement.type == "textarea") && event.srcElement.isDisabled == false )
		return true;

	// Alert user that context menu has been disabled
	event.keyCode = 0;
	event.cancelBubble = true;
	event.returnValue = false; 
	showPrompt ("Browser features have been disabled." + 
			"<br/>This operation is not allowed in FSFN." , "Close");
	return false; 
}

// Prevent user from typing ALT + LEFT ARROW, ALT + RIGHT ARROW,
// BACKSPACE on the page and F5 which would let the user navigate 
// the browser back, next, back and refresh respectively
function checkKeyDown(){
	try {
		if (acceleratorKey())
			return;
	} catch (e) {
		// Do nothing
		;
	}

	if ( event.keyCode == 122 ||
		 event.keyCode == 121 || 
		 event.keyCode == 117 || 
		 event.keyCode == 114 ||
		 event.keyCode == 116 ||
		(event.keyCode == 117) || (event.keyCode == 27) 
		|| (event.keyCode == 36 && event.altKey ) 
		|| (event.keyCode == 37 && event.altKey ) 
		|| (event.keyCode == 39 && event.altKey ) 
		|| (event.keyCode == 68 && event.altKey )
		|| (event.keyCode == 121 && event.shiftKey )  
		|| (event.keyCode == 9 && event.shiftKey && event.ctrlKey ) 
		|| (event.keyCode == 9 && event.ctrlKey ) 
		|| (event.keyCode == 69 && event.ctrlKey ) 
		|| (event.keyCode == 72 && event.ctrlKey ) 
		|| (event.keyCode == 73 && event.ctrlKey ) 
		|| (event.keyCode == 76 && event.ctrlKey ) 
		|| (event.keyCode == 78 && event.ctrlKey ) 
		|| (event.keyCode == 79 && event.ctrlKey ) 
		|| (event.keyCode == 8 && (event.srcElement.type != "text" &&
    	 			event.srcElement.type != "textarea" &&
    	 			event.srcElement.type != "password")) ) {
		return cancelAction();
	} else {
		return true;
	}
}

// Register the following events to call the above functions
document.onkeydown = checkKeyDown;
document.oncontextmenu = cancelAction;
document.onhelp = cancelAction;
